package com.leetcode;

/**
 * @author yijy
 * @description
 * @create 2021/4/30 下午8:50
 **/
public class HuiWen {

    public String longestPalindrome(String s) {
        if(null == s || s.length() < 2){
            return s;
        }
        int length = s.length();
        int start=0,end=0;
        for(int i=0;i<length; i++){
            int len1 = substringLen(s,i,i);
            int len2 = substringLen(s,i,i+1);
            int len = Math.max(len1,len2);
            if(len > end - start+1) {
                start = i - (len-1)/2;
                end = i + (len-1)/2;
            }
        }
        return s.substring(start,end+1);

    }

    int substringLen(String s, int l,int h){
        while(l >=0 && h<s.length() && s.charAt(l) == s.charAt(h)){
            l--;
            h++;
        }
        return h-l-1;
    }

    public static void main(String[] args) {
        System.out.println(new HuiWen().longestPalindrome("cbbd"));
    }
}
